import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决报错
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push (location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalReplace.call(this, location, onResolve, onReject)
  }
  return originalReplace.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '',
        name: 'Home',
        component: () => import('@/views/Home')
      },
      {
        path: '/My',
        name: 'My',
        component: () => import('@/views/My')
      },
      {
        path: '/SetUp',
        name: 'SetUp',
        component: () => import('@/views/SetUp')
      }
    ]
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('@/views/Login')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register')
  },
  {
    path: '/password-login',
    name: 'password-login',
    component: () => import('@/views/password-login')
  },
  // 搜索
  {
    path: '/SongSearch',
    name: 'SongSearch',
    component: () => import('@/views/SongSearch')
  },

  {
    path: '/SowingSongs',
    name: 'SowingSongs',
    component: () => import('@/components/SowingSongs')
  },
  {
    path: '/Mylike',
    name: 'MyLike',
    component: () => import('@/views/MyLike')
  },
  {
    path: '/RankingList',
    name: 'RankingList',
    component: () => import('@/views/RankingList')
  },
  {
    path: '/PersonalDetails', // 个人资料
    name: 'PersonalDetails',
    component: () => import('@/views/PersonalDetails')
  },
  {
    path: '/SongSheet',
    name: 'SongSheet',
    component: () => import('@/views/SongSheet')
  },
  // {
  //   path: '/MyNews', // 我的消息
  //   path: '/PersonalDetails',
  //   name: 'PersonalDetails',
  //   component: () => import('@/views/PersonalDetails')
  // },
  {
    path: '/MyNews',
    name: 'MyNews',
    component: () => import('@/views/MyNews')
  },
  {
    path: '/MyProfile', // 编辑资料
    name: 'MyProfile',
    component: () => import('@/views/MyProfile')
  },
  // 播放器
  {
    path: '/play:id',
    name: 'play',
    props: true,
    component: () => import('@/views/Play')
  },
  {
    path: '/like',
    name: 'like',
    component: () => import('@/views/like')
  },
  {
    path: '/MyProfile', // 我的消息
    name: 'MyProfile',
    component: () => import('@/views/MyProfile')
  },
  {
    path: '/Friends',
    name: 'Friends',
    component: () => import('@/views/Friends')
  }
]

const router = new VueRouter({
  routes
})

export default router
